#include <stdio.h>
int main()
{
    int n, m; int i, j; int flag ;
    int a[20]; int count = 0; int p;
    scanf("%d", &n);
    scanf("%d", &m);
    p=0;
    for (i = 1; i <= n; i++)
    {
        a[i - 1] = i;

    }
    while (p != n-1)
    {
        for (j = 0; j < n; j++)
        {
            flag = 1;

            if (a[j] != 0)
            {
                count++;
                flag = 0;
            }if (flag == 0&&count%m==0)
            {


                    a[j] = 0;
                    p=p+1;


            }
        }
    }

    for (i = 0; i < n; i++)
    {
        if (a[i] != 0)
        {
            printf("%d", a[i]);

        }

    }
    return 0;
}
